package ru.st.selenium.pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import ru.st.selenium.model.Film;

public abstract class AnyPage extends Page {

	public AnyPage(PageManager pages) {
		super(pages);
	}

	@FindBy(xpath = "//img[contains(@src,\"delete\")]")
	private WebElement deletemovie;

	public AnyPage clickDeleteMovie() {
		deletemovie.click();
		wait.until(alertIsPresent()).accept();
		return pages.AnyPage;
	}

	public AnyPage fillMovieForm(Film film) {
		String filmTitle = film.getTitle();
		driver.findElement(By.xpath("//input[@name='name']")).sendKeys(
				filmTitle);

		String filmImdbID = film.getImdb();
		driver.findElement(By.xpath("//input[@name='imdbid']")).sendKeys(
				filmImdbID);

		String filmYear = film.getYear();
		driver.findElement(By.xpath("//input[@name='year']"))
				.sendKeys(filmYear);

		String filmNotes = film.getNotes();
		driver.findElement(By.xpath("//input[@name='notes']")).sendKeys(
				filmNotes);

		return pages.AnyPage;
	}
}
